/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carrello.impl.controller.user;

import carrello.impl.controller.AbstractCTRL;
import carrello.model.entities.Product;

import carrello.model.association.CategoryAssociation;
import carrello.model.entities.Category;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Mehdi
 */
public class ProductCTRL extends AbstractCTRL{
    public static Product getProductById ( int productId ) {
        if ( productId >= 0 )
            return Product.getProductById ( productId );
        return null;
    }
    
    public static List getProductInfoById ( int productId ) {
        if ( productId >= 0 )
            return Product.getAllProductInfoById( productId );
        return null;
    }

    public static LinkedList<Product> getRelatedProducts(Product product) {
        LinkedList<Integer> lst = CategoryAssociation.getAssociatedCategories(product.getCategory().getCategory_id());
        LinkedList<Product> prods = new LinkedList<Product> ();
        for ( Integer i: lst ) {
            Set<Product> products = Category.getCategoryById(i).getProduct();
            prods.addAll(products);
        }
        if ( prods.size() == 0 )
            prods = null;
        return prods;
    }
}
